package com.hellogood.yaohuo.server.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.hellogood.yaohuo.server.db.ConnectionPool;
import com.hellogood.yaohuo.server.db.DBHelper;
import com.hellogood.yaohuo.shared.entity.GClass;

public class GClassDAO extends DBHelper {
	Logger log = Logger.getLogger(this.getClass());
	@Override
	public List<?> initializeObject(ResultSet rs) throws SQLException {
		List<GClass> list = new ArrayList<GClass>();
		if (rs != null) {
			while (rs.next()) {
				GClass c = new GClass();
				String clsCode = rs.getString("ClsCode");
				if(clsCode!=null){
					c.setClsCode(clsCode.trim());	
				}
				String clsName = rs.getString("ClsName");
				if(clsName!=null){
					c.setClsName(clsName.trim());
				}
				list.add(c);
			}
		}
		return list;
	}

	@SuppressWarnings("unchecked")
	public List<GClass> getAllGClass() {
		String hxDbName = ConnectionPool.hxDbName;
		String sql = "SELECT ClsCode,ClsName FROM " + hxDbName + "..GClass";
		List<?> list = super.query(sql);
		return (List<GClass>) list;
	}

	public Map<String, GClass> getGClassMap() {
		Map<String, GClass> map = new HashMap<String, GClass>();
		for (GClass c : getAllGClass()) {
			map.put(c.getClsCode(), c);
		}
		return map;
	}

}
